/*-------------------------------------------------------------
* 各种窗体的显示
* 
* 参考资料：
* 作者：伍伟
* 
* 修改时间：
*	2005.10.18	增加
*------------------------------------------------------------*/

var PARENT_ACTION_NOCHANGE = 0;	//父窗体不发生变化
var PARENT_ACTION_REFRESH = 1;	//父窗体进行刷新
var PARENT_ACTION_SUBMIT = 2;	//父窗体进行提交
var TOP_ACTION_REFRESH = 3;		//顶级窗体进行刷新
var TOP_ACTION_SUBMIT = 4;		//顶级窗体进行提交

var LAYER_WINDOW = 0;			//窗体的类型为 Layer
var DIALOG_WINDOW = 1;			//窗体的类型为 DialogWindow
var NEW_WINDOW = 2;				//窗体的类型为 Window

var Current_Window = -1;		//当前窗体的类型
var WindowName = "NewWin";		//当前窗体的名称

var screenwidth = window.screen.width;		//父框架窗体的宽度
var screenheight = window.screen.height;	//父框架窗体的高度

var currentWidth = 0;						//当前窗体的宽度
var currentHeight = 0;						//当前窗体的高度 

var historyWidth = 0;						//历史窗体的宽度(上一窗体)，以后将移到到frame.js中
var historyHeight = 0;						//历史窗体的高度(上一窗体)
var historyCaption = "弹出窗体";				//弹出窗体


document.ns = navigator.appName == "Netscape";	//所采用的浏览器
//switch layers for different browsers
var ie4 = (document.all) ? true : false;
var ns4 = (document.layers) ? true : false;
var ns6 = (document.getElementById && !document.all) ? true : false;

/*-------------------------------------------------------------
* 打开一个模态窗体：窗体的返回值表示窗体关闭后是否需要刷新页面
* 
* sUrl:窗体对应的链接页面
* paramObject：需要传入窗体的参数，可以是Js变量，也可以是HTML对象
* width：模态窗体的宽度
* height:模态窗体的高度
*/
function OpenDialogWindow(sUrl, paramObject,width,height){
	Current_Window = DIALOG_WINDOW;
	var sFeatures = "center:yes;dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;unadorned:0;scroll:no;";
	var command = false;
	command = window.showModalDialog(sUrl,paramObject, sFeatures);
	switch(command){
		case PARENT_ACTION_REFRESH:
			window.location.reload();
			break;
		case PARENT_ACTION_SUBMIT:
			document.forms[0].submit();
			break;
		case TOP_ACTION_REFRESH:
			top.window.location.reload();
			break;
		case TOP_ACTION_SUBMIT:
			top.document.forms[0].submit();
			break;
		default:
	}
}

/**
* 打开一个默认的模态窗体：默认的窗体的大小为Width：500；Hight：400
* 参考OpenDialogWindow(sUrl, paramObject,width,height)
* 
* sUrl:窗体对应的链接页面
* paramObject：需要传入窗体的参数，可以是Js变量，也可以是HTML对象
*/
function OpenDefaultDialogWindow(sUrl, paramObject){
	return OpenDialogWindow(sUrl, paramObject,500,400)
}

/**
* 打开一个新窗体：
* 
* sUrl:窗体对应的链接页面
* sName：窗体的名称
*		_blank: The sURL is loaded into a new, unnamed window.
*		_media: The sURL is loaded into the HTML content area of the Media Bar. Available in Internet Explorer 6 or later.
*		_parent: The sURL is loaded into the current frame's parent. If the frame has no parent, this value acts as the value _self.
*		_search: Available in Internet Explorer 5 and later. The sURL is opened in the browser's search pane.
*		_self: The current document is replaced with the specified sURL .
*		_top: sURL replaces any framesets that may be loaded. If there are no framesets defined, this value acts as the value _self.
*/
function openWindow(sUrl,sName){
	Current_Window = NEW_WINDOW;
	WindowName =sName;
    //Begin get the size of the default window
    var nNeedWidth = 990;
    var nNeedHeight = 690;
    if(screen.width < 1024){
        nNeedWidth = Math.round(nNeedWidth * 0.78125);
        nNeedHeight = Math.round(nNeedHeight * 0.78125);
    }
    var nCurrentWidth = 0;
    var nCurrentHeight = 0;

    var nCurrentTop = top.screenTop + 10;
    var nCurrentLeft = top.screenLeft + 10;
    if(nCurrentTop > 100 || nCurrentLeft > 100){
        nCurrentTop = 0;
        nCurrentLeft = 0;
    }

    if(nNeedWidth > screen.avilWidth) {
        nCurrentWidth = screen.avilWidth;
    } else {
        nCurrentWidth = nNeedWidth;
    }
    if(nNeedHeight > screen.avilHeight) {
        nCurrentHeight = screen.avilHeight;
    } else {
        nCurrentHeight = nNeedHeight;
    }
    var sFeature = 'toolbar=no,location=no,directories=no,status=yes,menubar=no,resizeable=yes';
    sFeature += ',left='+nCurrentLeft+',top='+nCurrentTop;
    sFeature += ',width=' + nCurrentWidth + ',height=' + nCurrentHeight;
    if(nCurrentWidth < nNeedWidth || nCurrentHeight < nNeedHeight) {
        sFeature += ',scrollbars=yes';
    } else {
        sFeature += ',scrollbars=no';
    }
    //End get the size of the default window

    oWin = window.open(sUrl, sName, sFeature);
    oWin.focus();
}

//打开一个层
function showlayer(){
	Current_Window = LAYER_WINDOW;
	var aArg = showlayer.arguments; //得到参数
	var nArg = aArg.length;
	var widthscale = (nArg>0)? aArg[0] : '';
    var heightscale = (nArg>1)? aArg[1] : '';
    var sUrl = (nArg>2)? escape(aArg[2]) : '';
	var layerobj = (nArg>3)? aArg[3] : eval("document.all." + WindowName);
	layerobj.style.display = "none";
	historyWidth = layerobj.style.width;
	historyHeight = layerobj.style.height;
	//TODO 到底是采用Screen的大小还是采用Body.innerHeight(innerWidth)大小，以及非IE浏览器时 需要继续测试。
	var layerWidth = Math.round((widthscale > 1) ? widthscale : ((widthscale <1) ? screenwidth*widthscale : getDefaultWidth()));
	var layerHeight = Math.round((heightscale > 1) ? heightscale : ((heightscale <1) ? screenheight*heightscale : getDefaultHeight()));

	currentWidth = layerWidth;
	currentHeight = layerHeight;
	if (document.ns)
	{
		//var layerobj = eval("document.driftLayer");
		myload(layerobj,layerWidth,layerHeight);
	} else {
		//layerobj.firstChild.src=unescape(sUrl)+"&width=" + layerWidth + "&height=" + layerHeight;
		document.all._layerFrame.src = unescape(sUrl);
		//layerobj.firstChild.src=unescape(sUrl);
		//document.all("_MMpanel").style.width = currentWidth;
		//document.all("_MMpanel").style.height = currentHeight;
		layerobj.firstChild.width = layerWidth;
		layerobj.firstChild.height = layerHeight;
		document.all("_layerFrame").height = layerHeight - 43;
		layerobj.style.width = layerWidth;
		layerobj.style.height = layerHeight;
		layerobj.style.display = "block";
		myload(layerobj,layerWidth,layerHeight);
	}
	layerobj.style.display = "block";
}

//重新定义层的大小
function resizelayer(){
	var aArg = resizelayer.arguments; //得到参数
	var nArg = aArg.length;
	var widthscale = (nArg>0)? aArg[0] : '';
    var heightscale = (nArg>1)? aArg[1] : '';
	var layerobj = ((nArg>2) && (aArg[2]!=null)) ? aArg[2] : eval("document.all." + WindowName);
	var sUrl = (nArg>3)? aArg[3] : '';
	layerobj.style.display = "none";
	historyWidth = layerobj.style.width;
	historyHeight = layerobj.style.height;
	//TODO 到底是采用Screen的大小还是采用Body.innerHeight(innerWidth)大小，以及非IE浏览器时 需要继续测试。
	var layerWidth = Math.round((widthscale > 1) ? widthscale : ((widthscale <1) ? screenwidth*widthscale : getDefaultWidth()));
	var layerHeight = Math.round((heightscale > 1) ? heightscale : ((heightscale <1) ? screenheight*heightscale : getDefaultHeight()));

	currentWidth = layerWidth;
	currentHeight = layerHeight;

	if (document.ns)
	{
		//var layerobj = eval("document.driftLayer");
		myload(layerobj,layerWidth,layerHeight);
	} else {
		if(sUrl != ""){
			document.all._layerFrame.src = unescape(sUrl);
			//layerobj.firstChild.src= unescape(sUrl);
		}
		//alert(document.all._layerFrame.src);
		//document.all("_MMpanel").style.width = currentWidth;
		//document.all("_MMpanel").style.height = currentHeight;
		layerobj.firstChild.width = layerWidth;
		layerobj.firstChild.height = layerHeight;
		document.all("_layerFrame").height = layerHeight - 43;
		layerobj.style.width = layerWidth;
		layerobj.style.height = layerHeight;
		myload(layerobj,layerWidth,layerHeight);
	}
	layerobj.style.display = "block";
}

/*-------------------------------------------------------------
* 关闭弹出的子窗体.
* 
* _return:表示窗体关闭后是否需要刷父的窗体页面
*/
function closeme(_return){
	switch(Current_Window){
		case LAYER_WINDOW:
			var layerobj = eval("document.all."+WindowName);
			layerobj.style.display = "none";
			setCaption("弹出窗体");
			//if(_return == PARENT_ACTION_SUBMIT)
			//	window.reload();
			switch(_return){
				case PARENT_ACTION_REFRESH:
					window.location.reload();
					break;
				case PARENT_ACTION_SUBMIT:
					alert(_return);
					document.forms[0].submit();
					break;
				case TOP_ACTION_REFRESH:
					top.window.location.reload();
					break;
				case TOP_ACTION_SUBMIT:
					top.document.forms[0].submit();
					break;
				default:
			}
			break;
		case DIALOG_WINDOW:
			window.returnValue = _return;
			window.close();
			break;
		case NEW_WINDOW:
			window.close();
			break;
		default:
	}
}

//子窗体内容进行回退
function goback(){
	switch(Current_Window){
		case LAYER_WINDOW:
			resizelayer(historyWidth,historyHeight);
			setCaption(historyCaption);
			history.go(-1);
			break;
		case DIALOG_WINDOW:
			break;
		case NEW_WINDOW:
			break;
		default:
	}
}

//为弹出窗体设置标题
function setCaption(title){
	historyCaption = document.all("_title").innerHTML;
	document.all("_title").innerHTML = title;
}

//初始化一个层
function initlayer(){
	var aArg = initlayer.arguments; //得到参数
	var nArg = aArg.length;
	var winLayer = (nArg>0)? aArg[0] : 'winLayer';
	var title = (nArg>1)? aArg[1] : '弹出窗体';
	WindowName = winLayer;
	if (document.ns)
	{
		document.write("<layer id=" +winLayer+ "><IFRAME border=0 width=100 height=20 id=layerFrame scrolling=no></IFRAME></layer>");
	} else {
		document.write("<div id=" + winLayer+" style=\"position: absolute;display:none;z-index: 1\">");
		document.write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
		document.write("	<tr>");
		document.write("		<td width=\"9\" height=\"9\"><img src=\"../images/layer_top_left.gif\" width=\"9\" height=\"9\"></td>");
		/**
		document.write("		<td rowspan=\"2\">");
		document.write("			<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
		document.write("				<tr>");
		document.write("				  <td width=\"10\"><img src=\"../images/dot.gif\" width=\"1\" height=\"1\"></td>");

		document.write("				  <td>标题：</td>");

		document.write("				  <td width=\"12\" align=\"right\"><img src=\"../images/sdot.gif\" width=\"12\" height=\"12\" title=\"关闭\"></td>");
		document.write("				  <td width=\"10\"><img src=\"../images/dot.gif\" width=\"1\" height=\"1\"></td>");
		document.write("				</tr>");
		document.write("			  </table>");
		</td>");
		document.write("		<td width=\"9\" height=\"9\"><img src=\"../images/layer_top-right.gif\" width=\"9\" height=\"9\"></td>");
		document.write("	</tr>");
		document.write("	<tr>"); 
		**/
		document.write("		<td background=\"../images/layer_top.gif\"></td>");
		document.write("		<td width=\"9\" height=\"9\"><img src=\"../images/layer_top_right.gif\" width=\"9\" height=\"9\"></td>");
		document.write("	</tr>");
		document.write("	<tr>");
		document.write("		<td background=\"../images/layer_left.gif\"></td>");
		document.write("		<td vAlign=top>");
		document.write("			<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
		document.write("			  <tr bgcolor=\"steelblue\">");
		document.write("				<td width=\"5\"><img src=\"../images/dot.gif\" width=\"1\" height=\"1\"></td>");//title为：填写您要查询和注册的域名/网址
		document.write("				<td height=\"24\" bgcolor=\"steelblue\"><font color=\"#FFFFFF\"><span><strong><label id=\"_title\">" + title +"</label></strong>&nbsp;&nbsp;</span></font></td>");
		document.write("				<td width=\"16\" align=\"right\" bgcolor=\"steelblue\"><img src=\"../images/iconerror.gif\" width=\"16\" height=\"16\" onClick=\"closeme()\"></td>");
		document.write("				<td width=\"5\"><img src=\"../images/dot.gif\" width=\"1\" height=\"1\"></td>");
		document.write("			  </tr>");
		document.write("			  <tr>");
		document.write("				<td colspan=\"4\" height=\"1\" bgcolor=\"#cccccc\"></td>");
		document.write("			 </tr></table");
		document.write("			<div>");
		document.write("			<IFRAME scrolling=no frameborder=0 hspace=0 vspace=0 width=100% marginWidth=0 marginHeight=0 id=\"_layerFrame\"></IFRAME>");
		document.write("		</div></td><td background=\"../images/layer_right.gif\"></td>");
		document.write("    </tr>");
		document.write("    <tr> ");
		document.write("		<td width=\"9\" height=\"9\"><img src=\"../images/layer_bottom_left.gif\" width=\"9\" height=\"9\"></td>");
		document.write("		<td background=\"../images/layer_bottom.gif\" height=\"9\"></td>");
		document.write("		<td width=\"9\" height=\"9\"><img src=\"../images/layer_bottom_right.gif\" width=\"9\" height=\"9\"></td>");
		document.write("  </tr>");
		document.write("</table>");
		document.write("</div>");
	}
}

//层的位置定位
function myload(obj, areawidth, areaheight)
{
	if (document.ns)
	{
		obj.pageY=(pageYOffset+window.innerHeight-areaheight)/2;
		obj.pageX=+(window.innerWidth-areawidth)/2;
		mymove(obj, areawidth, areaheight);
	} else {
		obj.style.top=(document.body.scrollTop+document.body.offsetHeight-areaheight)/2;
		obj.style.left=(document.body.offsetWidth-areawidth)/2;
		mymove(obj, areawidth, areaheight);
	}
}

//层的位置定位
function mymove(obj, areawidth, areaheight)
{
	if (document.ns)
	{
		obj.top=(pageYOffset+window.innerHeight-areaheight)/2;
		obj.left=pageXOffset+window.innerWidth;
		sobj=eval(obj);
		sareawidth=eval(areawidth);
		sareaheight=eval(areaheight);
		setTimeout("mymove(sobj,sareawidth,sareaheight);",50);
	} else {
		obj.style.top=(document.body.scrollTop+document.body.offsetHeight-areaheight)/2;
		obj.style.left=(document.body.scrollLeft+document.body.offsetWidth-areawidth)/2;
		sobj=eval(obj);
		sareawidth=eval(areawidth);
		sareaheight=eval(areaheight);
		setTimeout("mymove(sobj,sareawidth,sareaheight);",50)
	}
}

//在页面上增加一个浮动的帮助提示
function floatHelpTips(pid,note){
	document.write("<span onmouseover=\"showHelpTips('"+pid+"');image1.src='../images/ctx_question_active.gif';\" onmouseout=\"hideHelpTips('"+pid+"');image1.src='../images/ctx_question_inactive.gif';\"><img src=\"../images/ctx_question_inactive.gif\" name=\"image1\" width=\"17\" height=\"17\" border=\"0\"></span>"); 
	document.write("&nbsp;&nbsp;<span class=floathelp style='position: absolute;visibility:hidden' id=\""+pid+"\">" +note+ "</span>");
}

function hideHelpTips(lay) {
	if (ie4) {document.all[lay].style.visibility = "hidden";}
	if (ns4) {document.layers[lay].visibility = "hide";}
	if (ns6) {document.getElementById([lay]).style.display = "none";}
}

function showHelpTips(lay) {
	if (ie4) {document.all[lay].style.visibility = "visible";}
	if (ns4) {document.layers[lay].visibility = "show";}
	if (ns6) {document.getElementById([lay]).style.display = "block";}
}

//得到默认层的宽度
function getDefaultWidth(){
	return screenwidth>800 ? areaheight=500:areaheight=400;
}
//得到默认层的高度
function getDefaultHeight(){
	return screenheight>800 ? areawidth=400:areawidth=320;
}
